package com.example.demo.config;

import com.example.demo.controller.data.ReturnData;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 处理全局异常类
 */
@ControllerAdvice
public class HandlerException {
    @ExceptionHandler(Exception.class)
    public ResponseEntity<ReturnData>  handle(IllegalStateException ex ){
//        if(ex instanceof IllegalStateException){//判断是不是数据参数错误类型的异常
            return ResponseEntity.ok(ReturnData.error("请求参数错误",ex.toString()));
//        }
//        return ResponseEntity.ok(ReturnData.error("服务器异常",ex.toString()));
    }
}
